package com.roc.web.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.InterceptorRef;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.roc.page.BaseAction;
import com.roc.util.constant.ConfigProperties;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

/**
*@auhor   zbl
*@date    2016年11月27日 下午12:14:21
*@desc    说明
**/
@Component
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
@Namespace("/address")
public class AddressAction extends BaseAction{
	private static final long serialVersionUID = 1L;
	private  static Logger logger=LogManager.getLogger(AddressAction.class);
	
	private String proviceCode;
	private String cityCode;
	private String result;
	
	@Action(value = "getCityMap" )
	public void giveCityByProCode(){
		PrintWriter out=null;
		try {
			getResponse().setCharacterEncoding("utf-8");
			
			 out = getResponse().getWriter();
			 List<Map<String, String>> mapList=new ArrayList<Map<String,String>>();
			 mapList.add(ConfigProperties.getUnionCityProperties(proviceCode));
			result=JSONArray.fromObject(mapList).toString();
			out.print(result);
			
		} catch (IOException e) {
			logger.error("---获取城市失败---",e);
		}finally {
			if(out!=null){
				out.close();
			}
			
		}
	}
	
	@Action(value = "getAreaMap" )
	public void giveAreaByProCode(){
		PrintWriter out=null;
		try {
			getResponse().setCharacterEncoding("utf-8");
			
			 out = getResponse().getWriter();
			 List<Map<String, String>> mapList=new ArrayList<Map<String,String>>();
			 mapList.add(ConfigProperties.getUnAreaProperties(cityCode));
			result=JSONArray.fromObject(mapList).toString();
			out.print(result);
			
		} catch (IOException e) {
			logger.error("---获取地区失败---",e);
		}finally {
			if(out!=null){
				out.close();
			}
			
		}
	}
	
	public String getProviceCode() {
		return proviceCode;
	}

	public void setProviceCode(String proviceCode) {
		this.proviceCode = proviceCode;
	}

	public String getCityCode() {
		return cityCode;
	}

	public void setCityCode(String cityCode) {
		this.cityCode = cityCode;
	}



	public String getResult() {
		return result;
	}



	public void setResult(String result) {
		this.result = result;
	}
}
